package nsq

import (
	"github.com/nsqio/go-nsq"
	"time"
)

// Configuration NSQ配置
type Configuration struct {
	NSQAddress         string        `mapstructure:"nsq_address"`
	LookupAddress      string        `mapstructure:"lookup_address"`
	MaxInFlight        int           `mapstructure:"max_in_flight"`
	MsgTimeout         time.Duration `mapstructure:"msg_timeout"`
	Channel            string        `mapstructure:"channel"`
	ConsumeConcurrency int           `mapstructure:"concurrency"`
	// Maximum number of times this consumer will attempt to process a message before giving up
	// min:"0" max:"65535" default:"5"
	MaxAttempts uint16 `mapstructure:"max_attempts"`
	// Maximum duration when REQueueing (for doubling of deferred requeue)
	// min:"0" max:"60" default:"15"
	MaxRequeueDelay time.Duration `mapstructure:"max_requeue_delay"`
	//  min:"0" max:"60" default:"1m30s"
	DefaultRequeueDelay time.Duration `mapstructure:"default_requeue_delay"`

	Config *nsq.Config
}

func (c *Configuration) FillConfig() {
	c.Config = nsq.NewConfig()
	c.Config.MaxInFlight = c.MaxInFlight
	c.Config.MsgTimeout = c.MsgTimeout * time.Second
	c.Config.MaxAttempts = c.MaxAttempts
	c.Config.MaxRequeueDelay = c.MaxRequeueDelay * time.Minute
	c.Config.DefaultRequeueDelay = c.DefaultRequeueDelay * time.Minute
}
